home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6606 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: kryten.awinc.com!news
  2. From: jenna.design@awinc.com (jenna design)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: How to the size of a file in C ?
  5. Date: 10 Feb 1996 03:52:46 GMT
  6. Organization: A & W Internet Inc.
  7. Message-ID: <4fh4qe$487@kryten.awinc.com>
  8. References: <4ffeqa$pjh@brtph500.bnr.ca> <4ffs5g$a71@kryten.awinc.com>
  9. NNTP-Posting-Host: pme008.awinc.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14.  
  15. >#include <stdio.h>
  16. >
  17. >long GetFileSize (char *ptr_fName)
  18. >{
  19. > FILE *fp;
  20. > long f_size;
  21. >
  22. > if((fp = fopen(ptr_fName,"r"))==NULL)
  23. >        return 0;
  24. >
  25. > fseek(fp, 0L, SEEK_END);
  26. > f_size = ftell(fp);
  27. >
  28. > fclose(fp);
  29. >
  30. > return (f_size);
  31. >}
  32.  
  33.  
  34.  
  35.  
  36. Thanks to Darrell Grainger for pointing out a pitfall in the
  37. above code.
  38. The above function is fairly useless on 16 bit computers
  39. as if the returned value exceeds the maximum value a long
  40. variable can hold the variable will overflow.
  41.  
  42. in 16-bit LONG_MAX is defined as 32767
  43. in 32-bit LONG_MAX is defined as 2147483647
  44.  
  45. According to my on-line help, the stat()function may suit
  46. your task. According to Borland On-line Help  stat()
  47. is not in the ANSI-C standard. 
  48. Portability is listed as DOS|UNIX|WIN16|WIN32|OS2
  49.  
  50. Grainger, recommends reading the FAQ for this newsgroup.
  51.  
  52.  
  53.